+# add -DDEBUG_MEM to turn on memory allocation logging
CFLAGS=-g -Icoldsync
INSTALL_TARGETDIR=/usr/local/
if (pdb_AppendRecord(opdb, opdb_rec)) {
fatal(MYNAME ": libpdb couldn't append record\n");
}
+ xfree(rec);
}
struct hdr{
}
pdb_Write(opdb, fileno(file_out));
- free(htable);
+ xfree(htable);
}
wpt_tmp->shortname = mkshort(mkshort_handle, wpt_tmp->description);
waypt_add(wpt_tmp);
}
+ else {
+ waypt_free(wpt_tmp);
+ }
} else {
/* empty line */
description);
if (description)
- free (description);
+ xfree(description);
}
/* (strip out ampersands, commas, and quotes. */
/*********************************************************************/
char *
-csv_stringclean(const char *string, const char *chararray) {
+#ifdef DEBUG_MEM
+CSV_STRINGCLEAN(const char *string, const char *chararray, DEBUG_PARAMS)
+#else
+csv_stringclean(const char *string, const char *chararray)
+#endif
+{
char * p1;
char * p2;
const char * cp;
- char * tmp = xstrdup(string);
+ char * tmp = xxstrdup(string,file,line);
if ((! string) || (! chararray)) {
return (tmp);
/* usage: p = csv_stringtrim(string, "\"") */
/***********************************************************************************/
char *
+#ifdef DEBUG_MEM
+CSV_STRINGTRIM(const char *string, const char *enclosure,DEBUG_PARAMS)
+#else
csv_stringtrim(const char *string, const char *enclosure)
+#endif
{
static const char *p1 = NULL;
char *p2 = NULL;
- char * tmp = xstrdup(string);
+ char * tmp = xxstrdup(string,file,line);
size_t elen;
if (!strlen(string)) {
int enclosedepth = 0;
short int dfound;
+ if (tmp) {
+ xfree(tmp);
+ tmp = NULL;
+ }
+
if (!p) {
/* first pass thru */
p = stringstart;
}
}
- if (tmp) {
- free(tmp);
- tmp = NULL;
- }
-
/* the beginning of the string we start with (this pass) */
sp = p;
} else
if (strcmp(fmp->key, "ICON_DESCR") == 0) {
wpt->icon_descr = csv_stringtrim(s, "");
+ wpt->icon_descr_is_dynamic = 1;
} else
/* LATITUDE CONVERSIONS**************************************************/
if (elem == &xcsv_file.ifield) {
/* we've wrapped the queue. so stop parsing! */
+ while (s) {
+ s=csv_lineparse(NULL, "\xff","",linecount);
+ }
break;
}
queue *elem, *tmp;
if (wpt->shortname) {
- anyname = xstrdup(mkshort(mkshort_handle, wpt->shortname));
+ anyname = mkshort(mkshort_handle, wpt->shortname);
} else
if (wpt->description) {
- anyname = xstrdup(mkshort(mkshort_handle, wpt->description));
+ anyname = mkshort(mkshort_handle, wpt->description);
} else
if (wpt->notes) {
anyname = xstrdup(wpt->notes);
anyname = xstrdup("");
if ((anyname) && (global_opts.synthesize_shortnames)) {
- anyname = mkshort(mkshort_handle, anyname);
+ char *oldname = anyname;
+ anyname = mkshort(mkshort_handle, oldname);
+ xfree(oldname);
}
if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) {
fprintf (xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter);
if (shortname)
- free(shortname);
+ xfree(shortname);
if (description)
- free(description);
+ xfree(description);
if (anyname)
- free(anyname);
+ xfree(anyname);
index++;
}
/* function prototypes */
char *
+#ifndef DEBUG_MEM
csv_stringtrim(const char *string, const char *enclosure);
+#else
+CSV_STRINGTRIM(const char *string, const char *enclosure, DEBUG_PARAMS);
+#define csv_stringtrim( s, e ) CSV_STRINGTRIM( s, e, __FILE__, __LINE__);
+#endif
char *
csv_lineparse(const char *stringstart, const char *delimited_by, const char *enclosed_in, const int line_no);
char *
+#ifndef DEBUG_MEM
csv_stringclean(const char *string, const char *chararray);
+#else
+CSV_STRINGCLEAN(const char *string, const char *chararray,DEBUG_PARAMS);
+#define csv_stringclean(s,c) CSV_STRINGCLEAN(s,c,__FILE__,__LINE__);
+#endif
void
xcsv_data_read(void);
char *notes;
char *url;
char *url_link_text;
+ int icon_descr_is_dynamic;
const char *icon_descr;
time_t creation_time;
geocache_data gc_data;
typedef void (*ff_deinit) (void);
typedef void (*ff_read) (void);
typedef void (*ff_write) (void);
+
+#ifndef DEBUG_MEM
char * get_option(const char *iarglist, const char *argname);
+#else
+#define DEBUG_PARAMS const char *file, const int line
+char *GET_OPTION(const char *iarglist, const char *argname, DEBUG_PARAMS);
+#define get_option(iarglist, argname) GET_OPTION(iarglist, argname, __FILE__, __LINE__)
+#endif
typedef void (*filter_init) (char const *);
typedef void (*filter_process) (void);
typedef void (*route_trl)(const route_head *);
void waypt_add (waypoint *);
void waypt_del (waypoint *);
+void waypt_free (waypoint *);
void waypt_disp_all(waypt_cb);
-void route_disp_all(route_hdr, route_trl, waypt_cb);
+void waypt_flush(queue *);
+void waypt_flush_all();
unsigned int waypt_count(void);
route_head *route_head_alloc(void);
void route_add (waypoint *);
void route_add_wpt(route_head *rte, waypoint *wpt);
void route_add_head(route_head *rte);
+void route_disp_all(route_hdr, route_trl, waypt_cb);
+void route_free (route_head *);
+void route_flush( queue *);
+void route_flush_all();
/*
* All shortname functions take a shortname handle as the first arg.
* This is an opaque pointer. Callers must not fondle the contents of it.
*/
+#ifndef DEBUG_MEM
char *mkshort (void *, const char *);
void *mkshort_new_handle(void);
+#else
+char *MKSHORT(void *, const char *, DEBUG_PARAMS);
+void *MKSHORT_NEW_HANDLE(DEBUG_PARAMS);
+#define mkshort( a, b) MKSHORT(a,b,__FILE__, __LINE__)
+#define mkshort_new_handle() MKSHORT_NEW_HANDLE(__FILE__,__LINE__)
+#endif
void *mkshort_del_handle(void *h);
void setshort_length(void *, int n);
void setshort_badchars(void *, const char *);
void printposn(const coord *c, int is_lat);
filter_vecs_t * find_filter_vec(char *, char **);
+void free_filter_vec(filter_vecs_t *);
void disp_filters(void);
void disp_filter_vecs(void);
+#ifndef DEBUG_MEM
void *xcalloc(size_t nmemb, size_t size);
void *xmalloc(size_t size);
void *xrealloc(void *p, size_t s);
+void xfree(void *mem);
char *xstrdup(const char *s);
char *xstrappend(char *src, const char *new);
+#define xxcalloc(nmemb, size, file, line) xcalloc(nmemb, size)
+#define xxmalloc(size, file, line) xmalloc(size)
+#define xxrealloc(p, s, file, line) xrealloc(p,s)
+#define xxfree(mem, file, line) xfree(mem)
+#define xxstrdup(s, file, line) xstrdup(s)
+#define xxstrappend(src, new, file, line) xstrappend(src, new)
+#else /* DEBUG_MEM */
+void *XCALLOC(size_t nmemb, size_t size, DEBUG_PARAMS );
+void *XMALLOC(size_t size, DEBUG_PARAMS );
+void *XREALLOC(void *p, size_t s, DEBUG_PARAMS );
+void XFREE(void *mem, DEBUG_PARAMS );
+char *XSTRDUP(const char *s, DEBUG_PARAMS );
+char *XSTRAPPEND(char *src, const char *new, DEBUG_PARAMS );
+void debug_mem_open();
+void debug_mem_output( char *format, ... );
+void debug_mem_close();
+#define xcalloc(nmemb, size) XCALLOC(nmemb, size, __FILE__, __LINE__)
+#define xmalloc(size) XMALLOC(size, __FILE__, __LINE__)
+#define xrealloc(p, s) XREALLOC(p,s,__FILE__,__LINE__)
+#define xfree(mem) XFREE(mem, __FILE__, __LINE__)
+#define xstrdup(s) XSTRDUP(s, __FILE__, __LINE__)
+#define xstrappend(src,new) XSTRAPPEND(src, new, __FILE__, __LINE__)
+#define xxcalloc XCALLOC
+#define xxmalloc XMALLOC
+#define xxrealloc XREALLOC
+#define xxfree XFREE
+#define xxstrdup XSTRDUP
+#define xxstrappend XSTRAPPEND
+#endif /* DEBUG_MEM */
+
+
int case_ignore_strcmp(const char *s1, const char *s2);
description);
if (description)
- free (description);
+ xfree(description);
}
static int duplicate_shortname = 0;
static int duplicate_location = 0;
-char *snopt;
-char *lcopt;
+static char *snopt = NULL;
+static char *lcopt = NULL;
static
arglist_t dup_args[] = {
return (tree);
}
+void
+free_tree (btree_node *tree)
+{
+ if ( tree->left ) {
+ free_tree(tree->left);
+ }
+ if ( tree->right ) {
+ free_tree(tree->right);
+ }
+ xfree(tree);
+}
+
void
duplicate_process(void)
{
btree_node * newnode, * btmp, * ftmp, * sup_tree = NULL;
unsigned long crc = 0;
struct { char shortname[32]; char lat[13]; char lon[13]; } dupe;
+ waypoint * delwpt = NULL;
QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
waypointp = (waypoint *) elem;
btmp = addnode(sup_tree, newnode);
if (btmp == NULL) {
+ if ( delwpt ) {
+ waypt_free(delwpt);
+ }
+ delwpt = waypointp;
waypt_del(waypointp); /* collision */
- free(newnode);
+ xfree(newnode);
} else {
sup_tree = btmp;
}
}
-
- btmp = sup_tree->right;
-
- while (btmp) {
- ftmp = btmp;
- btmp = btmp->right;
- free(ftmp);
- }
-
- btmp = sup_tree->left;
-
- while (btmp) {
- ftmp = btmp;
- btmp = btmp->left;
- free(ftmp);
+
+ if ( delwpt ) {
+ waypt_free(delwpt);
}
- free(sup_tree);
+ free_tree(sup_tree);
}
void
res = strchr(vecname, ',');
if (res) {
- *opts = strchr(vecname, ',')+1;
+ *opts = res+1;
if (vec->vec->args) {
for (ap = vec->vec->args; ap->argstring; ap++){
*opts = NULL;
}
- free(v);
+ xfree(v);
return vec->vec;
}
- free(v);
+ xfree(v);
return NULL;
}
+void
+free_filter_vec( filter_vecs_t *fvec )
+{
+ if ( fvec->args && fvec->args->argval && *(fvec->args->argval) ) {
+ xfree(*(fvec->args->argval));
+ }
+}
+
/*
* Display the available formats in a format that's easy for humans to
* parse for help on available command line options.
while(--ntracks) {
GPS_Track_Del(&array[ntracks]);
}
- free(array);
+ xfree(array);
}
static void
for (i = 0; i < n; ++i) {
GPS_Way_Del(&way[i]);
}
- free(way);
+ xfree(way);
}
ff_vecs_t garmin_vecs = {
struct pdb *opdb;
struct pdb_record *opdb_rec;
+static char *tbuf = NULL;
+static char *tbufp = NULL;
static void
rd_init(const char *fname, const char *args)
wr_deinit(void)
{
fclose(file_out);
+ if ( tbuf )
+ xfree(tbuf);
}
static void
free_pdb(pdb);
}
+
static int
gcdb_add_to_rec(struct dbrec *rec, char *fldname, gcdb_rectype rectype, void *data)
{
int length;
- static char *tbuf;
- static char *tbufp;
static int rec_cnt;
+ if (!tbuf) {
+ tbuf = xcalloc(MAXRECSZ, 1);
+ tbufp = tbuf;
+ }
+
if (fldname == NULL) {
length = tbufp - tbuf;
be_write16(&rec->nflds, rec_cnt);
return length;
}
- if (!tbuf) {
- tbuf = xcalloc(MAXRECSZ, 1);
- tbufp = tbuf;
- }
-
be_write16(&rec->dbfld[rec_cnt].fldtype,rectype);
strncpy(rec->dbfld[rec_cnt].fldname, fldname, 4);
fatal(MYNAME ": libpdb couldn't append record\n");
}
- free(rec);
+ xfree(rec);
}
static void
void
geo_rd_deinit(void)
{
+ if ( cdatastr ) {
+ xfree(cdatastr);
+ }
fclose(fd);
}
case 3:
rtrim(s);
wpt_tmp->icon_descr = xstrdup(s);
+ wpt_tmp->icon_descr_is_dynamic = 1;
break;
default:
fprintf (stderr, "%s: Warning: unmapped data fields on line %d.\n",
double lon,lat;
char * shortname = NULL;
char *isrc, *owpt;
+ char *tmpstr;
lon = wpt->position.longitude.degrees;
lat = wpt->position.latitude.degrees;
if (( shortname == NULL ) && wpt->notes )
shortname = csv_stringclean(wpt->notes, ",\"");
- if ( shortname )
+ if ( shortname ) {
+ tmpstr = shortname;
shortname = mkshort(mkshort_wr_handle, shortname);
+ xfree(tmpstr);
+ }
}
fprintf(file_out, "%s %08.5f %08.5f",
if (wpt->icon_descr) {
char *s = csv_stringclean(wpt->icon_descr, " ");
fprintf(file_out, " %s", s);
- free(s);
+ xfree(s);
}
fprintf(file_out, "\n");
if (shortname)
- free (shortname);
+ xfree(shortname);
}
if (pdb_AppendRecord(opdb, opdb_rec)) {
fatal(MYNAME ": libpdb couldn't append record\n");
}
+ xfree(rec);
}
static void
strcpy(p, *(ep + 1));
strcpy(p + elen, xstr);
- free(xstr);
+ xfree(xstr);
p += elen;
}
}
if (in_icon && in_wpt) {
wpt_tmp->icon_descr = xstrdup(cdatastr);
+ wpt_tmp->icon_descr_is_dynamic = 1;
}
if (in_ele) {
sscanf(cdatastr, "%lf",
*cdata = xcalloc( *cdatalen + len + 1, 1);
if ( estr ) {
memcpy( *cdata, estr, *cdatalen);
- free( estr );
+ xfree( estr );
}
estr = *cdata + *cdatalen;
memcpy( estr, s, len );
static void
gpx_rd_deinit(void)
{
+ if ( cdatastr ) {
+ xfree(cdatastr);
+ }
fclose(fd);
}
if ( tag->cdata ) {
tmp_ent = gpx_entitize( tag->cdata );
fprintf( ofd, "%s", tmp_ent );
- free(tmp_ent);
+ xfree(tmp_ent);
}
if ( tag->child ) {
fprint_xml_chain(tag->child);
if ( tag->parentcdata ) {
tmp_ent = gpx_entitize(tag->parentcdata);
fprintf(ofd, "%s", tmp_ent );
- free(tmp_ent);
+ xfree(tmp_ent);
}
}
tag = tag->sibling;
}
}
+void free_gpx_extras( xml_tag *tag )
+{
+ xml_tag *next = NULL;
+ while ( tag ) {
+ if (tag->cdata) {
+ xfree(tag->cdata);
+ }
+ if (tag->child) {
+ free_gpx_extras(tag->child);
+ }
+ if (tag->parentcdata) {
+ xfree(tag->parentcdata);
+ }
+ next = tag->sibling;
+ xfree(tag);
+ tag = next;
+ }
+}
+
static void
gpx_waypt_pr(const waypoint *waypointp)
{
if (oname) {
tmp_ent = gpx_entitize(oname);
fprintf(ofd, "<name>%s</name>\n", tmp_ent);
- free(tmp_ent);
+ xfree(tmp_ent);
}
if (waypointp->description) {
fprintf(ofd, "<cmt>");
if (waypointp->url) {
tmp_ent = gpx_entitize(waypointp->url);
fprintf(ofd, "<url>%s</url>\n", tmp_ent);
- free(tmp_ent);
+ xfree(tmp_ent);
}
if (waypointp->url_link_text) {
tmp_ent = gpx_entitize(waypointp->url_link_text);
fprintf(ofd, "<urlname>%s</urlname>\n", tmp_ent );
- free(tmp_ent);
+ xfree(tmp_ent);
}
if (waypointp->icon_descr) {
tmp_ent = gpx_entitize(waypointp->icon_descr);
fprintf(ofd, "<sym>%s</sym>\n", tmp_ent );
- free(tmp_ent);
+ xfree(tmp_ent);
}
fprint_xml_chain( waypointp->gpx_extras);
wpt_tmp->position.latitude.degrees = lat;
waypt_add(wpt_tmp);
}
+ xfree(HxWpt);
}
#define MAX_STRINGLEN 255
static char strOut[MAX_STRINGLEN];
char strTmp[MAX_STRINGLEN];
+ char *shortstr = NULL;
if (sLen > MAX_STRINGLEN)
return (stIn);
setshort_length(mkshort_handle, sLen);
setshort_mustuniq(mkshort_handle, 0);
- strcpy(strTmp,mkshort(mkshort_handle, stIn));
+
+ shortstr = mkshort(mkshort_handle, stIn);
+ strcpy(strTmp,shortstr);
+ xfree(shortstr);
memset(strOut,' ', MAX_STRINGLEN);
strncpy (strOut,strTmp,strlen(strTmp));
}
fclose(file_out);
- free(HxWFile);
+ xfree(HxWFile);
}
if (pdb_AppendRecord(opdb, opdb_rec)) {
fatal(MYNAME ": libpdb couldn't append record\n");
}
+ xfree(rec);
}
static void
if(magfile_in)
fclose(magfile_in);
magfile_in = NULL;
+ if(mkshort_handle)
+ mkshort_del_handle(mkshort_handle);
+ mkshort_handle = NULL;
}
* alloc and chain those as we go.
*/
if (frag == 1) {
- mag_rte_head = xmalloc(sizeof (*mag_rte_head));
+ mag_rte_head = xcalloc(sizeof (*mag_rte_head),1);
QUEUE_INIT(&mag_rte_head->Q);
mag_rte_head->nelems = frags;
}
if (next_stop[0] == 0) {
break;
}
- rte_elem = xmalloc(sizeof (*rte_elem));
+ rte_elem = xcalloc(sizeof (*rte_elem),1);
QUEUE_INIT(&rte_elem->Q);
rte_elem->wpt_name = xstrdup(next_stop);
rte_elem->wpt_icon = xstrdup(abuf);
route_add_wpt(rte_head, waypt);
dequeue(&re->Q);
- free(re);
+ xfree(re);
}
}
return 0;
odesc,
icon_token);
mag_writemsg(obuf);
- free(owpt);
- free(odesc);
+ xfree(owpt);
+ xfree(odesc);
if (!is_file) {
if (mag_error) {
global_opts.objective = wptdata;
+#ifdef DEBUG_MEM
+ debug_mem_open();
+ debug_mem_output( "command line: " );
+ for ( argn = 1; argn < argc; argn++ ) {
+ debug_mem_output( "%s ", argv[argn] );
+ }
+ debug_mem_output( "\n" );
+#endif
+
waypt_init();
route_init();
case 'x':
optarg = argv[argn][2]
? argv[argn]+2 : argv[++argn];
-
fvecs = find_filter_vec(optarg, &fvec_opts);
if (fvecs) {
fvecs->f_init(fvec_opts);
fvecs->f_process();
fvecs->f_deinit();
+ free_filter_vec(fvecs);
}
break;
case 'D':
if (ovecs == NULL)
waypt_disp_all(waypt_disp);
+ waypt_flush_all();
+ route_flush_all();
+
+#ifdef DEBUG_MEM
+ debug_mem_close();
+#endif
+
exit(0);
}
}
void *
+#ifdef DEBUG_MEM
+MKSHORT_NEW_HANDLE(DEBUG_PARAMS)
+#else
mkshort_new_handle()
+#endif
{
int i;
- mkshort_handle *h = xcalloc(sizeof *h, 1);
+ mkshort_handle *h = xxcalloc(sizeof *h, 1, file, line);
for (i = 0; i < PRIME; i++)
QUEUE_INIT(&h->namelist[i]);
queue *e, *t;
int hash;
uniq_shortname *s = xcalloc(1, sizeof (uniq_shortname));
- s->orig_shortname = strdup(name);
+ s->orig_shortname = xstrdup(name);
hash = hash_string(name);
QUEUE_FOR_EACH(&h->namelist[hash], e, t) {
QUEUE_FOR_EACH(&hdr->namelist[i], e, t) {
uniq_shortname *s = (uniq_shortname *) e;
dequeue(e);
- free(s->orig_shortname);
- free(s);
+ xfree(s->orig_shortname);
+ xfree(s);
}
}
- free(hdr);
+ xfree(hdr);
}
}
/*
* Basically impelement strrchr.
*/
+ *replaced = 0;
for (l = strlen(istring); l > start; l--) {
if (strchr(vowels, istring[l-1])) {
char *ostring = xstrdup(istring);
strncpy(&ostring[l-1], &istring[l], 1+strlen(istring)-l);
ostring[strlen(istring)-1] = 0;
*replaced = 1;
- return ostring;
+ strcpy( istring, ostring );
+ xfree(ostring);
+ break;
}
}
- *replaced = 0;
return istring;
}
char *
+#ifdef DEBUG_MEM
+MKSHORT(void *h, const char *istring, DEBUG_PARAMS )
+#else
mkshort(void *h, const char *istring)
+#endif
{
- char *ostring = xstrdup(istring);
+ char *ostring = xxstrdup(istring, file, line);
char *nstring;
char *tstring;
char *cp;
if (( strlen(ostring) > hdl->target_len + 4) &&
(strncmp(ostring, "The ", 4) == 0 ||
strncmp(ostring, "the ", 4) == 0)) {
- nstring = xstrdup(ostring + 4);
- free(ostring);
+ nstring = xxstrdup(ostring + 4, file, line);
+ xfree(ostring);
ostring = nstring;
}
* Look at the back of the string for " by BLAH" and whack
* it there.
*/
- nstring = xstrdup(ostring);
+ nstring = xxstrdup(ostring, file, line);
l = strlen (nstring);
while (l > 0) {
if (strncmp(&nstring[l], " by ",4) == 0) {
}
l --;
}
- free(ostring);
+ xfree(ostring);
ostring = nstring;
if (!hdl->whitespaceok) {
/*
* Eliminate Whitespace
*/
- tstring = xstrdup(ostring);
+ tstring = xxstrdup(ostring, file, line);
l = strlen (tstring);
cp = ostring;
for (i=0;i<l;i++) {
*cp++ = tstring[i];
}
}
- free(tstring);
+ xfree(tstring);
*cp = 0;
}
* Eliminate chars on the blacklist.
* Characters that aren't ASCII are never OK.
*/
- tstring = xstrdup(ostring);
+ tstring = xxstrdup(ostring, file, line);
l = strlen (tstring);
cp = ostring;
for (i=0;i<l;i++) {
*cp++ = tstring[i];
}
*cp = 0;
- free(tstring);
+ xfree(tstring);
/*
* Toss vowels to approach target length, but don't toss them
* both.
*/
- tstring = xstrdup(ostring);
-
/*
* Delete vowels starting from the end. If it fits, quit stomping
* them. If we run out of string, give up.
#define MYNAME "MXF"
-static void *mkshort_handle;
+static void *mkshort_handle= NULL;
static void
mxf_set_style()
fclose(xcsv_file.xcsvfp);
xcsv_destroy_style();
+ if ( mkshort_handle)
+ mkshort_del_handle(mkshort_handle);
+ mkshort_handle = NULL;
}
ff_vecs_t mxf_vecs = {
#define MYNAME "OZI"
-static void *mkshort_handle;
+static void *mkshort_handle = NULL;
static void
/* outfields are infields */
if (xcsv_file.ofield)
- free(xcsv_file.ofield);
+ xfree(xcsv_file.ofield);
xcsv_file.ofield = &xcsv_file.ifield;
xcsv_file.ofield_ct = xcsv_file.ifield_ct;
if (xcsv_file.xcsvfp)
fclose(xcsv_file.xcsvfp);
- xcsv_destroy_style();
+ xcsv_destroy_style();
+ if ( mkshort_handle)
+ mkshort_del_handle(mkshort_handle);
+ mkshort_handle = NULL;
}
ff_vecs_t ozi_vecs = {
char latdir, londir;
long alt;
char alttype;
- char icon[3] = {0};
char date[10];
char time[9];
waypoint *wpt_tmp;
if (londir == 'W') lon = -lon;
wpt_tmp->position.longitude.degrees = lon/100.0;
wpt_tmp->position.latitude.degrees = lat/100.0;
- wpt_tmp->icon_descr = xstrdup(icon);
waypt_add(wpt_tmp);
}
}
/* convert radians to integer feet */
dist = (int)((((dist * 180.0 * 60.0) / M_PI) / 1.1516) * 5280.0);
- if (dist <= pos_dist)
+ if (dist <= pos_dist) {
waypt_del(comp[i]);
+ waypt_free(comp[i]);
+ }
}
if (comp)
- free (comp);
+ xfree(comp);
}
void
position_init(const char *args) {
char *fm;
- const char *p;
+ char *p;
p = get_option(args, "distance");
/* distance is meters */
pos_dist *= 3.2802;
}
+ xfree(p);
}
}
filter_vecs_t position_vecs = {
position_init,
position_process,
- position_deinit
+ position_deinit,
+ NULL
};
fwrite(&tbuf[0], 1, 1, psp_file_out); /* null */
}
- free (shortname);
- free (description);
+ xfree(shortname);
+ xfree(description);
}
static void
ENQUEUE_TAIL(&rte->waypoint_list, &wpt->Q);
}
+void
+route_free(route_head *rte)
+{
+ if ( rte->rte_name ) {
+ xfree(rte->rte_name);
+ }
+ if ( rte->rte_desc ) {
+ xfree(rte->rte_desc);
+ }
+ waypt_flush(&rte->waypoint_list);
+ xfree(rte);
+}
+
void
route_disp (const route_head *rh, waypt_cb cb )
{
(*rt)(rhp);
}
}
+void
+route_flush(queue *head)
+{
+ queue *elem, *tmp;
+ route_head *last = NULL;
+
+ QUEUE_FOR_EACH(head, elem, tmp) {
+ if ( last ) {
+ route_free(last);
+ }
+ last = (route_head *)elem;
+ }
+ if ( last ) {
+ route_free(last);
+ }
+ QUEUE_INIT(head);
+}
+void
+route_flush_all()
+{
+ route_flush(&my_route_head);
+}
+
}
if (i != 11) {
- free(wpt_tmp);
+ xfree(wpt_tmp);
fprintf (stderr, "%s: WARNING - extracted %d fields from line %d. \nData on line ignored.\n",
MYNAME, i, linecount);
} else {
if (description)
- free(description);
+ xfree(description);
if (shortname)
- free(shortname);
+ xfree(shortname);
}
static void
static void
tpg_wr_deinit(void)
{
+ mkshort_del_handle(mkshort_handle);
fclose(tpg_file_out);
}
/* and finally 2 unknown bytes */
fwrite(unknown2, 1, 2, tpg_file_out);
- free (shortname);
- free (description);
+ xfree(shortname);
+ xfree(description);
}
static void
#include <stdlib.h>
#include <ctype.h>
+#ifdef DEBUG_MEM
+#define DEBUG_FILENAME "/tmp/gpsbabel.debug"
+
+static FILE *debug_mem_file = NULL;
+void
+debug_mem_open()
+{
+ debug_mem_file = fopen( DEBUG_FILENAME, "a" );
+}
+
+void
+debug_mem_output(char *format, ...)
+{
+ va_list args;
+ va_start( args, format );
+ if ( debug_mem_file ) {
+ vfprintf( debug_mem_file, format, args );
+ fflush( debug_mem_file );
+ }
+ va_end( format );
+}
+
+void
+debug_mem_close()
+{
+ if ( debug_mem_file ) {
+ fclose(debug_mem_file);
+ }
+ debug_mem_file = NULL;
+}
+#endif
+
void *
+#ifdef DEBUG_MEM
+XMALLOC(size_t size, DEBUG_PARAMS)
+#else
xmalloc(size_t size)
+#endif
{
void *obj = malloc(size);
+#ifdef DEBUG_MEM
+ debug_mem_output( "malloc, %x, %d, %s, %d\n",
+ obj, size, file, line );
+#endif
if (!obj) {
fatal("gpsbabel: Unable to allocate %d bytes of memory.\n", size);
}
}
void *
+#ifdef DEBUG_MEM
+XCALLOC(size_t nmemb, size_t size, DEBUG_PARAMS)
+#else
xcalloc(size_t nmemb, size_t size)
+#endif
{
void *obj = calloc(nmemb, size);
+#ifdef DEBUG_MEM
+ debug_mem_output( "calloc, %x, %d, %d, %s, %d\n",
+ obj, nmemb, size, file, line );
+#endif
if (!obj) {
fatal("gpsbabel: Unable to allocate %d bytes of memory.\n", size);
return obj;
}
+void
+#ifdef DEBUG_MEM
+XFREE( void *mem, DEBUG_PARAMS )
+#else
+xfree( void *mem )
+#endif
+{
+ free(mem);
+#ifdef DEBUG_MEM
+ debug_mem_output( "free, %x, %s, %d\n",
+ mem, file, line );
+#endif
+}
+
char *
+#ifdef DEBUG_MEM
+XSTRDUP(const char *s, DEBUG_PARAMS )
+#else
xstrdup(const char *s)
+#endif
{
char *o = strdup(s);
+#ifdef DEBUG_MEM
+ debug_mem_output( "strdup, %x, %x, %s, %d\n",
+ o, s, file, line );
+#endif
if (!o) {
fatal("gpsbabel: Unable to allocate %d bytes of memory.\n", strlen(s));
}
void *
+#ifdef DEBUG_MEM
+XREALLOC(void *p, size_t s, DEBUG_PARAMS )
+#else
xrealloc(void *p, size_t s)
+#endif
{
char *o = realloc(p,s);
+#ifdef DEBUG_MEM
+ debug_mem_output( "realloc, %x, %x, %x, %s, %d\n",
+ o, p, s, file, line );
+#endif
if (!o) {
fatal("gpsbabel: Unable to realloc %d bytes of memory.\n", s);
* For an allocated string, realloc it and append 's'
*/
char *
+#ifdef DEBUG_MEM
+XSTRAPPEND(char *src, const char *new, DEBUG_PARAMS)
+#else
xstrappend(char *src, const char *new)
+#endif
{
size_t newsz;
if (!src) {
- return(xstrdup(new));
+ return xxstrdup(new, file, line);
}
newsz = strlen(src) + strlen(new) + 1;
- src = xrealloc(src, newsz);
+ src = xxrealloc(src, newsz, file, line);
strcat(src, new);
return src;
*opts = NULL;
}
- free(v);
+ xfree(v);
return vec->vec;
}
- free(v);
+ xfree(v);
return NULL;
}
* Modelled approximately after getenv.
*/
char *
+#ifdef DEBUG_MEM
+GET_OPTION(const char *iarglist, const char *argname, DEBUG_PARAMS)
+#else
get_option(const char *iarglist, const char *argname)
+#endif
{
size_t arglen = strlen(argname);
char *arglist;
* The caller mustn't free or otherwise get froggy with
* this data.
*/
+ if ( rval ) {
+ rval = xxstrdup(rval,file, line);
+ }
+ xfree(arglist);
return rval;
}
return NULL;
}
+
+void
+waypt_free( waypoint *wpt )
+{
+ if (wpt->shortname) {
+ xfree(wpt->shortname);
+ }
+ if (wpt->description) {
+ xfree(wpt->description);
+ }
+ if (wpt->notes) {
+ xfree(wpt->notes);
+ }
+ if (wpt->url) {
+ xfree(wpt->url);
+ }
+ if (wpt->url_link_text) {
+ xfree(wpt->url_link_text);
+ }
+ if (wpt->icon_descr && wpt->icon_descr_is_dynamic) {
+ xfree((char *)(void *)wpt->icon_descr);
+ }
+ if (wpt->gpx_extras) {
+ free_gpx_extras(wpt->gpx_extras);
+ }
+ xfree(wpt);
+}
+
+void
+waypt_flush( queue *head )
+{
+ queue *elem, *tmp;
+ waypoint *last = NULL;
+
+ QUEUE_FOR_EACH(head, elem, tmp) {
+ if ( last ) {
+ waypt_free(last);
+ }
+ last = (waypoint *)elem;
+ }
+
+ if ( last ) {
+ waypt_free(last);
+ }
+
+ QUEUE_INIT(head);
+}
+void
+waypt_flush_all()
+{
+ if ( mkshort_handle ) {
+ mkshort_del_handle( mkshort_handle );
+ }
+ waypt_flush(&waypt_head);
+}
if (xcsv_file.is_internal == 0) {
ogp = (ogue_t *)elem;
if (ogp->val)
- free(ogp->val);
+ xfree(ogp->val);
}
if (elem)
- free(elem);
+ xfree(elem);
}
/* destroy the epilogue */
if (xcsv_file.is_internal == 0) {
ogp = (ogue_t *)elem;
if (ogp->val)
- free(ogp->val);
+ xfree(ogp->val);
}
if (elem)
- free(elem);
+ xfree(elem);
}
/* destroy the ifields */
if (xcsv_file.is_internal == 0) {
fmp = (field_map_t *) elem;
if (fmp->key)
- free(fmp->key);
+ xfree(fmp->key);
if (fmp->val)
- free(fmp->val);
+ xfree(fmp->val);
if (fmp->printfc)
- free(fmp->printfc);
+ xfree(fmp->printfc);
}
if (elem)
- free(elem);
+ xfree(elem);
}
/* destroy the ofields, if they are not re-mapped to ifields. */
if (xcsv_file.is_internal == 0) {
fmp = (field_map_t *) elem;
if (fmp->key)
- free(fmp->key);
+ xfree(fmp->key);
if (fmp->val)
- free(fmp->val);
+ xfree(fmp->val);
if (fmp->printfc)
- free(fmp->printfc);
+ xfree(fmp->printfc);
}
if (elem)
- free(elem);
+ xfree(elem);
}
if (xcsv_file.ofield)
- free(xcsv_file.ofield);
+ xfree(xcsv_file.ofield);
}
if (xcsv_file.is_internal == 0) {
/* other alloc'd glory */
if (xcsv_file.field_delimiter)
- free(xcsv_file.field_delimiter);
+ xfree(xcsv_file.field_delimiter);
if (xcsv_file.record_delimiter)
- free(xcsv_file.record_delimiter);
+ xfree(xcsv_file.record_delimiter);
if (xcsv_file.badchars)
- free(xcsv_file.badchars);
+ xfree(xcsv_file.badchars);
}
/* return everything to zeros */
if (ISSTOKEN(sbuff, "FIELD_DELIMITER")) {
sp = csv_stringtrim(&sbuff[16], "\"");
cp = get_char_from_constant_table(sp);
- if (cp)
+ if (cp) {
xcsv_file.field_delimiter = xstrdup(cp);
+ xfree(sp);
+ }
else
xcsv_file.field_delimiter = sp;
} else
if (ISSTOKEN(sbuff, "RECORD_DELIMITER")) {
sp = csv_stringtrim(&sbuff[17], "\"");
cp = get_char_from_constant_table(sp);
- if (cp)
+ if (cp) {
xcsv_file.record_delimiter = xstrdup(cp);
+ xfree(sp);
+ }
else
xcsv_file.field_delimiter = sp;
} else
if (ISSTOKEN(sbuff, "BADCHARS")) {
sp = csv_stringtrim(&sbuff[9], "\"");
cp = get_char_from_constant_table(sp);
- if (cp)
+ if (cp) {
xcsv_file.badchars = xstrdup(cp);
+ xfree(sp);
+ }
else
xcsv_file.badchars = sp;
} else
i++;
s = csv_lineparse(NULL, ",", "", linecount);
- }
+ }
xcsv_ifield_add(key, val, pfc);
/* if we have no output fields, use input fields as output fields */
if (xcsv_file.ofield_ct == 0) {
if (xcsv_file.ofield)
- free(xcsv_file.ofield);
+ xfree(xcsv_file.ofield);
xcsv_file.ofield = &xcsv_file.ifield;
xcsv_file.ofield_ct = xcsv_file.ifield_ct;
}
static void
xcsv_rd_init(const char *fname, const char *args)
{
- const char *p;
+ char *p;
/*
* if we don't have an internal style defined, we need to
fatal(MYNAME ": XCSV input style not declared. Use ... -i xcsv,style=path/to/file.style\n");
xcsv_read_style(p);
+ xfree(p);
}
xcsv_file.xcsvfp = fopen(fname, "r");
static void
xcsv_wr_init(const char *fname, const char *args)
{
- const char * p;
+ char * p;
mkshort_handle = mkshort_new_handle();
/* if we don't have an internal style defined, we need to
fatal(MYNAME ": XCSV output style not declared. Use ... -o xcsv,style=path/to/file.style\n");
xcsv_read_style(p);
+ xfree(p);
/* set mkshort options from the command line */
if (global_opts.synthesize_shortnames) {
p = get_option(args, "snlen");
- if (p)
+ if (p) {
setshort_length(mkshort_handle, atoi(p));
+ xfree(p);
+ }
p = get_option(args, "snwhite");
- if (p)
+ if (p) {
setshort_whitespace_ok(mkshort_handle, atoi(p));
+ xfree(p);
+ }
p = get_option(args, "snupper");
- if (p)
+ if (p) {
setshort_mustupper(mkshort_handle, atoi(p));
+ xfree(p);
+ }
setshort_badchars(mkshort_handle, xcsv_file.badchars);
}
fclose(xcsv_file.xcsvfp);
xcsv_destroy_style();
+ mkshort_del_handle(mkshort_handle);
}
ff_vecs_t xcsv_vecs = {
#include "csv_util.h"
#define MYNAME "XMAPWPT"
-static void *mkshort_handle;
+static void *mkshort_handle= NULL;
static void
xmapwpt_set_style()
/* outfields are infields */
if (xcsv_file.ofield)
- free(xcsv_file.ofield);
+ xfree(xcsv_file.ofield);
xcsv_file.ofield = &xcsv_file.ifield;
xcsv_file.ofield_ct = xcsv_file.ifield_ct;
fclose(xcsv_file.xcsvfp);
xcsv_destroy_style();
+ if ( mkshort_handle )
+ mkshort_del_handle(mkshort_handle);
+ mkshort_handle = NULL;
}
ff_vecs_t xmapwpt_vecs = {